package package06章_面向对象编程_基础._04oop.exer5_objArr;

/**
 * @ClassName: package06章_面向对象编程_基础.oop04.exer5_objArr1.StudentTest
 * @Author 86132
 * @Package package06章_面向对象编程_基础.oop04.exer5_objArr
 * @Date 2024/2/10 17:32
 * @description:
 */
public class e_6_06StudentTest {
    public static void main(String[] args) {
        //创建Student[]
        Student[] students = new Student[20]; //String[] strs = new String[20];

        //使用循环，给数组的元素赋值
        for (int i = 0; i < students.length; i++) {
            students[i] = new Student();
            //给每一个学生对象的number、state、score属性赋值
            students[i].number = i + 1;
            students[i].state = (int)(Math.random() * 6 + 1);
            students[i].score = (int)(Math.random() * 101);

        }
        //需求1：打印出3年级(state值为3）的学生信息
        for (int i = 0; i < students.length; i++) {
            System.out.println(i);
            if (students[i].state == 3) {
                Student stu = students[i];

                System.out.println(stu.show());
            }
        }


        //需求2：使用冒泡排序按学生成绩排序，并遍历所有学生信息
        //排序前遍历
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i].show());
        }

        System.out.println("************************11===============");


        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - 1 - i; j++) {
                if (students[j].score > students[j + 1].score) {
                    Student temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }

        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i].show());
        }

    }
}
